package thread.threadpool;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @author yuisama
 * @date 2022/07/12 16:52
 **/
public class ThreadPoolClose {
    public static void main(String[] args) {
        ExecutorService pool = new ThreadPoolExecutor(3,6,10, TimeUnit.SECONDS,
                new LinkedBlockingQueue<>(3),
                new ThreadPoolExecutor.AbortPolicy());
        for (int i = 0; i < 6; i++) {
            pool.submit(() -> {
                while (true) {
                    System.out.println(Thread.currentThread().getName() + "is working...");
                    Thread.sleep(1000);
                }
            });
        }
        // 主线程休眠6秒关闭线程池
        try {
            Thread.sleep(6000);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        pool.shutdownNow();
    }
}